<?php
class xdata
{

	
	//每页显示条数
	public $per_num_s = array(
		10,20,30,50,100,200
	);
	
	//返回处理状态
	public function handle_status($i){
		return $this->x_data_handle_status[$i];
	}	
	
	//返回分配状态
	public function distribute_status($i){
		return $this->x_data_distribute_status[$i];
	}
	
	//处理结果
	public function handle_result($i){
		return $this->x_data_handle_result[$i];
	}
	
	/*
	* 获取页面显示页码数
	* total	数据总条数	cur_page 当前页数	row	每页显示条数	url 查询地址
	* 返回分页html页面	
	*/
	public function show_page($total,$row,$cur_page,$url){
		$page_num = ceil($total/$row);
		$show_page = array();
		
		//分页显示
		if($total != 0){
			if($cur_page-2 <= 1){
				$startshow = 1;
				$endshow = 5;
			}else if($cur_page-2 >= 2 ){
				$startshow = $cur_page-2;
				if($cur_page+2 <= $page_num)
					$endshow = $cur_page+2;
				else
					$endshow = $page_num;
			} 
			
			if($cur_page+2 >= $page_num ){
				$startshow = $page_num-4;
				if($startshow<=0){
					$startshow = 1;
				}
			}
			if($page_num<5){
				$endshow = $page_num;
			}
		}else{				//如果数据为空
			$startshow = 0;
			$endshow = 0;
		}

		$page = '';
		if($total != 0){
			$page .= '<div class="fenye" style="height:40px;">';
			$page .= '  <ul class="pager">';
		   if($cur_page != 1){
				$page .= '		<li class="previous" link="'.$url.'"><a href="#">上一页</a></li>';
				$page .= '		<li class="page_query" attr_page="1" link="'.$url.'"><a href="#">首页</a></li>';
		   }
			  
			for($i=$startshow;$i<=$endshow;$i++){
				$page .= '		<li class="page_query ';
				if($i == $cur_page){
				$page .= 'active';
				}
				$page .='" attr_page="'.$i.'" link="'.$url.'">';
				$page .= '			<a href="#">'.$i.'</a>';
				$page .= '		</li>';
			}
			
			if($cur_page != $page_num){
				$page .= '		<li class="page_query" attr_page="'.$page_num.'" link="'.$url.'"><a href="#">尾页</a></li>';
				$page .= '		<li class="next" link="'.$url.'"><a href="#">下一页</a></li>';
			}
			$page .= '  </ul>';
			$page .= '	</div>';
		}
		
		return $page;
	}
	
}